/**
 * qiangungun.com Inc.
 * Copyright (c) 2004-2014 All Rights Reserved.
 */
package com.qiangungun.xts.service.facade.model;

import org.apache.commons.lang.StringUtils;

/**
 * 
 *
 * @author czhou3306@gmail.com
 * @version $Id: ResultCode.java, v 0.1 2014年12月29日 下午8:40:29 czhou3306@gmail.com Exp $
 */
public enum ResultCode {

    /**成功*/
    //  SUCCESS("QE001100000", "成功"),

    /**db幂等异常*/
    IDEMPOTENT_ERROR("QE001100001", "db幂等异常"),

    /**事务id数据格式错误*/
    ACTIVITY_ID_FORMAT_ERROR("QE001100002", "事务id数据格式错误"),

    /**查询不到分支事务*/
    NO_ACTIONS("QE001100003", "查询不到分支事务"),

    /**分支事务二阶段失败*/
    ACTION_TWO_PHASE_ERROR("QE001100004", "分支事务二阶段失败"),

    /**主事务状态异常*/
    ACTIVITY_STATE_ERROR("QE001100005", "主事务状态异常"),

    /**主事务更新异常*/
    ACTIVITY_UPDATE_ERROR("QE001100006", "主事务更新异常"),

    /**分布式事务只能在本地事务中开启*/
    NO_LOCAL_TRANSACTION("QE001100007", "分布式事务只能在本地事务中开启"),

    /**系统异常*/
    SYSTEM_ERROR("QE001200999", "系统异常"),

    /**系统异常*/
    UNKNOWN("QE001200998", "未知"),

    ;

    private String code;
    private String message;

    /**
     * 构造器
     * @param code
     * @param message
     */
    private ResultCode(String code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * Getter method for property <tt>code</tt>.
     * 
     * @return property value of code
     */
    public String getCode() {
        return code;
    }

    /**
     * Getter method for property <tt>message</tt>.
     * 
     * @return property value of message
     */
    public String getMessage() {
        return message;
    }

    /**
     * 
     * 
     * @param code
     * @return
     */
    public static ResultCode getByCode(String code) {
        for (ResultCode resultCode : values()) {
            if (StringUtils.equals(resultCode.getCode(), code)) {
                return resultCode;
            }
        }
        return UNKNOWN;
    }

}
